package com.snow.common.controller;

import com.snow.conditions.Order;
import com.snow.conditions.QueryDescription;
import com.snow.conditions.QueryOrderType;
import com.snow.jpa.model.BasePageParams;
import com.snow.jpa.model.IBaseSearchParams;
import com.snow.model.IdParams;
import com.snow.common.entity.SystemConfigItemEntity;
import com.snow.common.service.SystemConfigItemService;
import com.snow.view.PageData;
import com.snow.view.WebResponse;
import lombok.Getter;
import lombok.Setter;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/system-config-item")
public class SystemConfigItemController {

    private final SystemConfigItemService systemconfigitemService;

    public SystemConfigItemController(SystemConfigItemService systemconfigitemService) {
        this.systemconfigitemService = systemconfigitemService;
    }

    @Getter
    @Setter
    @QueryDescription(sort = @Order(value = "createTime", type = QueryOrderType.desc))
    public static class PageParams extends BasePageParams {
    }

    @PostMapping("/page")
    public WebResponse<PageData<SystemConfigItemEntity>> page(@RequestBody PageParams params) {
        return WebResponse.success(systemconfigitemService.page(params));
    }

    @PostMapping("/create")
    public WebResponse<SystemConfigItemEntity> create(@RequestBody SystemConfigItemEntity entity) {
        return WebResponse.success(systemconfigitemService.save(entity));
    }

    @PostMapping("/update")
    public WebResponse<SystemConfigItemEntity> update(@RequestBody SystemConfigItemEntity entity) {
        return WebResponse.success(systemconfigitemService.update(entity));
    }

    @PostMapping("/delete")
    public WebResponse<SystemConfigItemEntity> delete(@RequestBody IdParams params) {
        return WebResponse.success(systemconfigitemService.delete(params.getId()));
    }

    @Getter
    @Setter
    public static class SearchParams implements IBaseSearchParams {
    }

    @PostMapping("/search")
    public WebResponse<List<SystemConfigItemEntity>> search(@RequestBody SearchParams params) {
        return WebResponse.success(systemconfigitemService.search(params));
    }
}
